package com.uk.ui.fatura;

import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import com.uk.data.containers.TarifaContainer;
import com.uk.data.entities.Tarifa;
import com.uk.ui.ColumnGeneratorUtils;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Table;

public class TarifaInfo extends GridLayout{

	private TarifaContainer tarifaContainer;
	private Table tarifaListTable = new Table();
	
	private IndexedContainer indexedContainer = new IndexedContainer();
	
	public TarifaInfo(FaturaForm faturaForm){
		super(3,1);
		this.tarifaContainer = TarifaContainer.createFromEjb(faturaForm.getFaturaBean(), true);
		
		indexedContainer.addContainerProperty("Kodi", String.class, "");
		indexedContainer.addContainerProperty("Pershkrimi", Date.class, null);
		indexedContainer.addContainerProperty("Njesia", Boolean.class, false);
		indexedContainer.addContainerProperty("Sasia", String.class, "");
		indexedContainer.addContainerProperty("Cmimi", String.class, "");
		indexedContainer.addContainerProperty("Vlera", String.class, "");
		
		Collection<Tarifa> col = this.getTarifaContainer().getItemIds();
		for (Iterator iterator = col.iterator(); iterator.hasNext();) {
			Tarifa tarifa = (Tarifa) iterator.next();
			Object id = indexedContainer.addItem();
			indexedContainer.getContainerProperty(id, "Kodi").setValue(tarifa.getKodi());
			indexedContainer.getContainerProperty(id, "Pershkrimi").setValue(tarifa.getKodi());
			indexedContainer.getContainerProperty(id, "Njesia").setValue(tarifa.getKodi());
			if (tarifa.isUk())
				indexedContainer.getContainerProperty(id, "Sasia").setValue(tarifa.getKodi());
			else
				indexedContainer.getContainerProperty(id, "Kodi").setValue(tarifa.getKodi());
			
		}
		
		
		tarifaListTable.setContainerDataSource(this.tarifaContainer);
		tarifaListTable.setVisibleColumns(TarifaContainer.COL_FOR_FATURA);
		tarifaListTable.setColumnHeaders(TarifaContainer.COL_FOR_FATURA_HEADER);
		tarifaListTable.setPageLength(4);
	
		tarifaListTable.setSelectable(true);
		tarifaListTable.setImmediate(true);
		tarifaListTable.setSortDisabled(true);
		tarifaListTable.setWidth("600px");
		tarifaListTable.addGeneratedColumn("aplikoTVSH", ColumnGeneratorUtils.PoJoColumnGenerator());
		this.addComponent(tarifaListTable);
	}

	public TarifaContainer getTarifaContainer() {
		return tarifaContainer;
	}

	public Table getTarifaListTable() {
		return tarifaListTable;
	}
}
